package tests;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;

import java.util.concurrent.TimeUnit;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;	
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class L02MalUsuario {
  private WebDriver driver;
  private String baseUrl;
  private StringBuffer verificationErrors = new StringBuffer();

  @Before
  public void setUp() throws Exception {
    driver = new FirefoxDriver();
    baseUrl = "https://accounts.google.com/";
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
  }

  @Test
  public void testL02MalUsuario() throws Exception {
    driver.get(baseUrl + "/ServiceLogin?service=mail&passive=true&rm=false&continue=http://mail.google.com/mail/&scc=1&ltmpl=default&ltmplcache=2");
    setData("prueba.software.erronea@gmail.com");
    setData("prueba.softwareErronea@gmail.com");
    setData("pruebaSoftwareErronea@gmail.com");
  }

private void setData(String mail) {
	driver.findElement(By.id("Email")).clear();
    driver.findElement(By.id("Email")).sendKeys(mail);
    driver.findElement(By.id("Passwd")).clear();
    driver.findElement(By.id("Passwd")).sendKeys("passwordtest123456");
    driver.findElement(By.id("signIn")).click();
    // Warning: verifyTextPresent may require manual changes
    try {
    	assertEquals("The username or password you entered is incorrect. ?", driver.findElement(By.id("errormsg_0_Passwd")).getText());
    } catch (Error e) {
      verificationErrors.append(e.toString());
    }
}

  @After
  public void tearDown() throws Exception {
    driver.quit();
    String verificationErrorString = verificationErrors.toString();
    if (!"".equals(verificationErrorString)) {
      fail(verificationErrorString);
    }
  }
  }